package demo.boat.boatSystem.controller;

import demo.boat.boatSystem.entity.ShpVessels;
import demo.boat.boatSystem.service.GoodsManageService;
import demo.boat.handler.BussinessException;
import demo.boat.response.Result;
import demo.boat.response.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/findLabels")
public class GoodsManageController {
    @Autowired
    private GoodsManageService goodsManageService;
    @GetMapping("/getVvyNm/{vvlNm}")
    public Result getVvyNm(@PathVariable String vvlNm) {
        List<ShpVessels> lstVvls = goodsManageService.findLabels(vvlNm);
        if(lstVvls.size() == 0) {
            throw new BussinessException(ResultCode.VVL_NOT_FOUND.getCode(), ResultCode.VVL_NOT_FOUND.getMessage());
        } else {
            return Result.ok().data("lstVvls", lstVvls);
        }
    }
    @GetMapping("/findBls/{vvyNm}")
    public Result findBls(@PathVariable String vvyNm) {
        List<ShpVessels> lstBls = goodsManageService.findBls(vvyNm);
        if(lstBls.size() == 0) {
            throw new BussinessException(ResultCode.VVL_NOT_FOUND.getCode(), ResultCode.VVL_NOT_FOUND.getMessage());
        } else {
            return Result.ok().data("lstBls", lstBls);
        }
    }
}
